Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nice_things/utility/dirname.sh

dirname

Since 0.3.0 · Source

import "{ dirname }" from nice_things/utility/dirname.sh

Synopsis
dirname <pathname>

Configuration

Description
Print the directory portion of <pathname>, with the last component removed.

This is a pure sh implementation of the dirname utility specified in POSIX.

Being an implementation of a CLI utility, this function prints the result to stdout. If you want to assign the result to a variable, consider using the faster dir_name function instead.

Options

Operands
<pathname>: A path name.

Stdin

Stdout
The resulting pathname is printed to stdout, trailed by a line-feed character.

Stderr

Exit status
0: Successful completion.

Abort

Usage examples

dirname /usr/bin/ # /usr